﻿@using LightSO.CMS.Model.EasyUI
@{
    Datagrid Datagrid = null;
    if (ViewBag.Datagrid == null)
    {
        Datagrid = Datagrid.Create(ViewBag);
    }
    else
    {
        Datagrid = ViewBag.Datagrid;
    }
    string version = "201705221034";
}


<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>@ViewBag.Title</title>
    @Html.Partial("~/Views/Shared/Shared.cshtml")

    <script type="text/javascript">
    @RenderSection("EnumDefine", false)
    var columns_@(Datagrid.Id) = [
        @if(Datagrid.Columns.Count>0)
        {
        @:[
            var i = 0;
            foreach (var item in Datagrid.Columns)
            {
                Column col = item.Value;
                @:{
                        @:  field: '@(col.Id)', title: '@Html.Raw(col.Title.Replace("'", ""))', width: @(col.Width), hidden: @((col.Id == "Id" ? "true" : (col.Hidden ? "true" : "false"))), sortable: @(col.Sortable ? "true" : "false"), align: '@(col.Align.ToString().ToLower())', nowrap: @(col.NoWrap ? "true" : "false"),
                    @:  formatter: function(value, row, index){
                                        string columnName = col.Id;
                        if (!string.IsNullOrWhiteSpace(columnName))
                        {
                            var script = RenderSection(string.Format("{0}ColumnFormat", columnName), false);
                            if(script != null)
                            {
                                System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(@"</?script[^<>]*>");
                                @Html.Raw(regex.Replace(script.ToHtmlString(), string.Empty));
                                @:value = this.formatter(value, row, index);
                                    }
                        }
                        @:return typeof(value) != "string" && value == 0 ? "" : value;
                                   @:}
                        @:}
                    i++;
                if (i != Datagrid.Columns.Count)
                {
                    @:,
                    }
            }
        @:]
            }
    ];

    var rowStyler_@Datagrid.Id = function (index, row) {
            @{
                var rowStyler = RenderSection("RowStyler", false);
                if (rowStyler != null)
                {
                    System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(@"</?script[^<>]*>");
                    @Html.Raw(regex.Replace(rowStyler.ToHtmlString(), string.Empty));
                    @:return this.rowStyler(index, row);
                }
            }
    };

    var onClickRowEvent_@Datagrid.Id = function (index, row) {
            @{
            var onClickRowEvent = RenderSection("OnClickRow", false);
            if (onClickRowEvent != null)
            {
                System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(@"</?script[^<>]*>");
                @Html.Raw(regex.Replace(onClickRowEvent.ToHtmlString(), string.Empty));
                @:this.onClickRow(index, row);
            }
        }
    };

    var onDblClickRowEvent_@Datagrid.Id = function (index, row) {
            @{
                var onDblClickRowEvent = RenderSection("OnDblClickRow", false);
                if (onDblClickRowEvent != null)
                {
                    System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(@"</?script[^<>]*>");
                    @Html.Raw(regex.Replace(onDblClickRowEvent.ToHtmlString(), string.Empty));
                    @:this.onDblClickRow(index, row);
                }
            }
    };

    $(function () {
        easymvc.createDatagrid('@(Datagrid.Id)', '@(Html.Raw(Datagrid.Url))');
    });
    </script>
@if (!string.IsNullOrWhiteSpace(Datagrid.ScriptSrc))
{
    <script type="text/javascript" src="@Datagrid.ScriptSrc?version=@version"></script>
}
</head>
<body>


    <table id="@(Datagrid.Id)" data-options="singleSelect:@(Datagrid.SingleSelect ? "true" : "false")"></table>
    @RenderBody()

    @*右键菜单*@
    @if (!Datagrid.IsNoNeedToolBar)
    {
        <div id="popupmenu_@(Datagrid.Id)" class="easyui-menu" style="width:120px;">
            @RenderSection("PopupMenu", required: false)
            <div class="menu-sep"></div>
            <div id="menuItemReload" onclick="easymvc.datagridReload('@(Datagrid.Id)');" data-options="iconCls:'icon-reload'">刷新</div>
        </div> 
    }


    @*工具条面板组*@
    @if (!Datagrid.IsNoNeedToolBar)
    {
        <div id="datagrid_toolbar_@(Datagrid.Id)" style="display:none;">
            @*按钮组*@
            @{var buttons = RenderSection("ToolbarButtonsGroup", false);}
            @if (buttons != null)
            {
                <div class="datagrid-toolbar">
                    @Html.Raw(buttons.ToHtmlString())
                </div>
            }
            @{var filter = RenderSection("ToolbarFilter", false);}
            @if (filter != null)
            {
                <div class="datagrid-toolbar">
                    @Html.Raw(filter.ToHtmlString())
                </div>
            }
            @*工具条菜单*@
            <div class="datagrid-toolbar" style="border-bottom-width:0px;">
                @RenderSection("ToolbarMenu", false)
                <a id="btnDatagridReload" onclick="easymvc.datagridReload('@(Datagrid.Id)');" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-reload',plain:true">刷新</a>
            </div>
        </div> 
    }
    

    <script type="text/javascript">
        $(function(){
            $("table[id='@(Datagrid.Id)']").parent(".datagrid-view").attr("onselectstart","return false").css({"-moz-user-select":"none"});
        });
    </script>
</body>
</html>


